﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace MyLinksMenu.Layouts
{
	public partial class ManageMyLinks : LayoutsPageBase
	{
		private string _WebUrl;

		protected string WebUrl
		{
			get
			{
				return _WebUrl;
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			_WebUrl = SPContext.Current.Web.Url;

			DialogMaster master = (DialogMaster)Master;
			master.OkButton.Click += new EventHandler(OkButton_Click);
		}

		protected void OkButton_Click(object sender, EventArgs e)
		{
			CloseDialog();
		}

		private void CloseDialog()
		{
			string script = @"if (window.parent.frameElement && window.parent.frameElement.commitPopup) {
								window.parent.frameElement.commitPopup(1);
							}
							else if (window.frameElement && window.frameElement.commitPopup) {
								window.frameElement.commitPopup(1);
							}
							else {
								window.parent.close();
							}";

			this.Page.Response.Clear();
			this.Page.Response.Write("<script type=\"text/javascript\">" + script + "</script>");
			this.Page.Response.End();
		}
	}
}
